<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>后台管理</title>
	<link rel="stylesheet" th:href="@{/static/layui/css/layui.css}" media="all"/>
	<link rel="stylesheet" th:href="@{/static/css/footer.css}" media="all"/>
	<link rel="stylesheet" th:href="@{/static/css/thesame.css}" media="all"/>
	<link rel="stylesheet" th:href="@{/static/css/tree.css}" media="all"/>
	<link rel="stylesheet" th:href="@{/static/css/popCss.css}" media="all"/>
	<link rel="stylesheet" th:href="@{/static/user/css/user.css}"  media="all"/>
	<style type="text/css">
        /*取消选中效果*/
		div{
	    -moz-user-select:none;/*火狐*/
	    -webkit-user-select:none;/*webkit浏览器*/
	    -ms-user-select:none;/*IE10*/
	    -khtml-user-select:none;/*早期浏览器*/
	      user-select:none;
		}
		.layui-form-checkbox[lay-skin="primary"]{padding-left: 0px;}
		.add-mess-child .tree-con-box .tree-one{height: 300px;}
    </style>
</head>
<script th:inline="javascript">var basePath = [[${#httpServletRequest.getContextPath()}]];</script>
<body>
<div class="add-title pad25px"><span onclick="returnUserList()" style="cursor: pointer;"  class="mr10px"><img th:src="@{/static/img/return_icon.png}"></span><span id="actionTitle">新建用户</span></div>
<div class="new-add-box new-add-box-width bgWhite box-shadows border-radius4">
	<div class="new-add-box-scroll">
		<div class="add-mess add-mess-mb mar25px">
			<article>
				<input type="hidden" name="userNo"/>
				<div class="add-mess-child">
					<div>
						<label><em class="red">*</em>登录账号：</label>
					</div>
					<div class="add-mess-form">
						<p><input type="text" style="width: 280px;" maxlength="20" onkeyup="value=value.replace(/[~!`?\/<>|@#$%^&*()+_=:]/g,'')" name="loginName" placeholder="请输入"></p>
					</div>
				</div>
				<div id="treeTwo" class="add-mess-child">
					<div>
						<label><em class="red">*</em>所属组织：</label>
					</div>
					<div class="add-mess-form">
						<p class="add-mess-form-tree"><input type="text" style="color: #757575;" placeholder="请选择" class="form-select" id="selectParentOrg"></p>
						<div class="tree-con-box" style="height: 260px;">
						</div>
					</div>
				</div>
				<div class="add-mess-child">
					<div>
						<label><em class="red">*</em>用户姓名：</label>
					</div>
					<div class="add-mess-form">
						<p><input type="text" style="width: 280px;" maxlength="10" onkeyup="value=value.replace(/[~!`?\/<>|@#$%^&*()+_=:]/g,'')" name="userName" placeholder="请输入"></p>
					</div>
				</div>
				<div class="add-mess-child">
					<div>
						<label>部门：</label>
					</div>
					<div class="add-mess-form">
						<p><input type="text" style="width: 280px;" maxlength="10" name="dept" onkeyup="value=value.replace(/[~!`?\/<>|@#$%^&*()+_=:]/g,'')" placeholder="请输入"></p>
					</div>
				</div>
				<div class="add-mess-child">
					<div>
						<label><em class="red">*</em>手机号码：</label>
					</div>
					<div class="add-mess-form">
						<p><input type="text" style="width: 280px;" maxlength="11" name="phone" onkeyup="value=value.replace(/[^\d]/g,'')" placeholder="请输入"></p>
					</div>
				</div>
				<div class="add-mess-child">
					<div>
						<label>职位：</label>
					</div>
					<div class="add-mess-form">
						<p><input type="text" style="width: 280px;" maxlength="20" onkeyup="value=value.replace(/[~!`?\/<>|@#$%^&*()+_=:]/g,'')" name="post" placeholder="请输入"></p>
					</div>
				</div>
			</article>
			<div class="add-mess-child" style="clear: both">
				<div>
					<label>授权角色：</label>
				</div>
				<ul class="left add-mess-child-ul" style="width: 80%;">
					<p id="roleConBtn" onclick="roleCon()">
						<em><img th:src="@{/static/user/img/icon_add.png}" class="mr5px"></em>
						<span>添加</span>
					</p>
				</ul>
			</div>
			<div id="treeThree" class="add-mess-child">
				<div>
					<label>数据权限：</label>
				</div>
				<div>
					<div class="tree-con-box layui-form border1px" style="top: 0; height: 300px; left: 80px; width: 400px; box-shadow: none;">
					</div>
				</div>
			</div>
		</div>
	</div>
</div>
<div class="layui-footer layui-footer-one">
	<div class="btn-con textCenter">
		<span class="btn-one" style="cursor: pointer;"  onclick="returnUserList()">取&nbsp;消</span>
		<span class="btn-two" style="cursor: pointer;"  id="addBtn"  onclick="addUser()">提&nbsp;交</span>
	</div>
</div>


<script type="text/javascript" th:src="@{/static/js/jquery-2.1.3.min.js}" charset="utf-8"></script>
<script type="text/javascript" th:src="@{/static/js/layuiCon.js}" charset="utf-8"></script>
<script type="text/javascript" th:src="@{/static/layui/layui.js}" charset="utf-8"></script>
<script type="text/javascript" th:src="@{/static/js/date.js}" charset="utf-8"></script>
<script type="text/javascript" th:src="@{/static/js/treeThree.js}" charset="utf-8"></script>

<script>

	//layer初始化
	var layer;
	layui.use('layer', function(){
		layer = layui.layer;
	});
	//初始化选择角色id
	var selectRoleStr=',';

	$(function(){
		$('.add-person ul li').click(function(){
			$(this).addClass('cur-green').siblings().removeClass('cur-green');
		})
		//授权机构树初始化
		authOrgInit();
		//选择机构树初始化
		addOrgInit();
		//修改初始化（用户userNo存在时，绑定修改信息）
		editUserInit();
	})

	/**
	 * 添加选择机构-机构
	 */
	function addOrgSelect(obj){
		var name = $(obj).html();
		var orgId = $(obj).data("orgid");
		if(orgId==10){name="/";}
		$("#selectParentOrg").val(name);
		$("#selectParentOrg").data("orgid",orgId);
		$('#treeTwo .tree-con-box').hide();
	}

	/**
	 * 添加组织弹层初始化
	 */
	function addOrgInit(){
		//修改title为新建组织
		$("#actionTitle").html("新建用户");
		$.ajax({
			type:"post",
			url:basePath+"/org/getAllOrg",
			dataType:"json",
			success:function(data){
				var str="";
				$.each(data.children,function(index,ao){
					if(ao.isChildExist=='1' && data.children!=null && data.children.length>0){
						str+='<ul class="tree-one" style="height: 260px">';
						$.each(ao.children,function(index,ao1){
							str+='<li>';
							str+='<div class="tree-children">';
							str+='<div>';
							if(ao1.isChildExist=='1'){
								str+='<p class="tree-arrow cursor"><img src="'+basePath+'/static/org/img/icon_select_down.png"></p>';
								str+='<p onclick="addOrgSelect(this);event.cancelBubble =true" data-orgid="'+ao1.orgId+'">'+ao1.orgName+'</p>';
							}else{
								str+='<p style="margin-left:17px" onclick="addOrgSelect(this);event.cancelBubble =true" data-orgid="'+ao1.orgId+'">'+ao1.orgName+'</p>';
							}
							str+='</div>';
							str+='</div>';
							if(ao1.isChildExist=='1' && ao.children!=null && ao.children.length>0){
								str+='<ul class="tree-two">';
								$.each(ao1.children,function(index,ao2){
									str+='<li>';
									str+='<div class="tree-children">';
									str+='<div>';
									if(ao2.isChildExist=='1'){
										str+='<p class="tree-arrow cursor"><img src="'+basePath+'/static/org/img/icon_select_down.png"></p>';
										str+='<p onclick="addOrgSelect(this);event.cancelBubble =true" data-orgid="'+ao2.orgId+'">'+ao2.orgName+'</p>';
									}else{
										str+='<p style="margin-left:8px" onclick="addOrgSelect(this);event.cancelBubble =true" data-orgid="'+ao2.orgId+'">'+ao2.orgName+'</p>';
									}
									str+='</div>'
									str+='</div>';
									if(ao2.isChildExist=='1' && ao2.children!=null && ao2.children.length>0){
										str+='<ul class="tree-three">';
										$.each(ao2.children,function(index,ao3){
											str+='<li>';
											str+='<div class="tree-children">';
											str+='<div>';
											if(ao3.isChildExist=='1'){
												str+='<p class="tree-arrow cursor"><img src="'+basePath+'/static/org/img/icon_select_down.png"></p>';
												str+='<p onclick="addOrgSelect(this);event.cancelBubble =true" data-orgid="'+ao3.orgId+'">'+ao3.orgName+'</p>';
											}else{
												str+='<p style="margin-left:8px" onclick="addOrgSelect(this);event.cancelBubble =true" data-orgid="'+ao3.orgId+'">'+ao3.orgName+'</p>';
											}
											str+='</div>'
											str+='</div>';
											if(ao3.isChildExist=='1' && ao3.children!=null && ao3.children.length>0){
												str+='<ul class="tree-four">';
												$.each(ao3.children,function(index,ao4){
													str+='<li>';
													str+='<div class="tree-children">';
													str+='<div>';
													str+='<p style="margin-left:8px" onclick="addOrgSelect(this);event.cancelBubble =true" data-orgid="'+ao4.orgId+'">'+ao4.orgName+'</p>';
													str+='</div>'
													str+='</div>';
													str+='</li>';
												})
												str+='</ul>'
											}
											str+='</li>';
										})
										str+='</ul>';
									}
									str+='</li>';
								})
								str+='</ul>';
							}
							str+='</li>';
						});
						str+='</ul>';
					}
					str+='';

				});
				$("#treeTwo .tree-con-box").html(str);
				$("#treeTwo .tree-con-box").hide();
				//选择机构数点击功能初始化
				treeTwoInit();
			}
		})
	}

	function treeTwoInit(){
		$('#treeTwo .tree-one ul').hide();
		$('#treeTwo .tree-one div.tree-children div .tree-arrow').unbind().click(function() {
			$('.tree-one div.tree-children div').removeClass("current");
			//$(this).parent().addClass('current');
			$(this).parent().parent('div.tree-children').nextAll('ul').slideToggle(300);
			if ($(this).parent().find('img').attr('src') == basePath+'/static/org/img/icon_select_up.png') {
				$(this).parent().find('img').attr('src', basePath+'/static/org/img/icon_select_down.png');
				//$(this).parent().siblings().find('img').attr('src', 'img/icon_select_up.png')
				$('.tree-one div.tree-children div').removeClass("current");
			} else {
				$(this).parent().find('img').attr('src', basePath+'/static/org/img/icon_select_up.png');
			}
		})
		$('#treeTwo .add-mess-child .tree-con-box').hide();
		$('#treeTwo .add-mess-form-tree').unbind().click(function(){
			$(this).next().slideToggle();
		})
	}

	/**
	 * 返回列表
	 */
	function returnUserList(){
		window.location.href=basePath+"/user/listPage";
	}

	/**
	 * 授权机构树初始化
	 */
	function authOrgInit(){
		var userNo = '[[${userNo}]]';
		$.ajax({
			type: "post",
			url: basePath + "/org/getAllAuthOrg",
			dataType: "json",
			data: {"userNo": userNo},
			success: function (data) {
				var str = "";
				$.each(data.children, function (index, ao) {
					if (ao.isChildExist == '1' && data.children.length > 0) {
						str += '<ul class="tree-one">';
						$.each(ao.children, function (index, ao1) {
							str += '<li>';
							str += '<div class="tree-children">';
							str += '<div>';
							str += '<p class="mr5px"><input lay-filter="switchTest" type="checkbox" '+(ao1.authType == 0?' ':checked="checked")+' data-state="0" data-parentorgid="' + ao1.parentOrgId + '" id="' + ao1.orgId + '" name="" lay-skin="primary"></p>';
							str += ao1.isChildExist == '1'?'<p class="tree-arrow cursor"><img src="'+ basePath +'/static/user/img/icon_select_down.png"></p><p>' + ao1.orgName + '</p>':'<p style="margin-left: 8px;margin-right: 6px;">' + ao1.orgName + '</p>';
							str += '</div>';
							str += '</div>';
							if (ao1.isChildExist == '1' && ao.children.length > 0) {
								str += '<ul class="tree-two">';
								$.each(ao1.children, function (index, ao2) {
									str += '<li>';
									str += '<div class="tree-children">';
									str += '<div>';
									str += '<p class="mr5px"><input lay-filter="switchTest" type="checkbox" '+(ao2.authType == 0?' ':checked="checked")+' data-state="0" data-parentorgid="' + ao2.parentOrgId + '" id="' + ao2.orgId + '" name="" lay-skin="primary"></p>';
									str += ao2.isChildExist == '1'?'<p class="tree-arrow cursor"><img src="'+ basePath +'/static/user/img/icon_select_down.png"></p><p>' + ao2.orgName + '</p>':'<p style="margin-left: 8px;margin-right: 6px;">' + ao2.orgName + '</p>';
									str += '</div>'
									str += '</div>';
									if (ao2.isChildExist == '1' && ao1.children.length > 0) {
										str += '<ul class="tree-three">';
										$.each(ao2.children, function (index, ao3) {
											str += '<li>';
											str += '<div class="tree-children">';
											str += '<div>';
											str += '<p class="mr5px"><input lay-filter="switchTest" type="checkbox" '+(ao3.authType == 0?' ':checked="checked")+' data-state="0" data-parentorgid="' + ao3.parentOrgId + '" id="' + ao3.orgId + '" name="" lay-skin="primary"></p>';
											str += ao3.isChildExist == '1'?'<p class="tree-arrow cursor"><img src="'+ basePath +'/static/user/img/icon_select_down.png"></p><p>' + ao3.orgName + '</p>':'<p style="margin-left: 8px;margin-right: 6px;">' + ao3.orgName + '</p>';
											str += '</div>';
											str += '</div>';
											if (ao3.isChildExist == '1' && ao2.children.length > 0) {
												str += '<ul class="tree-four">';
												$.each(ao3.children, function (index, ao4) {
													str += '<li>';
													str += '<div class="tree-children">';
													str += '<div>';
													str += '<p class="mr5px"><input lay-filter="switchTest" type="checkbox" '+(ao4.authType == 0?' ':checked="checked")+' data-state="0" data-parentorgid="' + ao4.parentOrgId + '" id="' + ao4.orgId + '" name="" lay-skin="primary"></p>';
													str += ao4.isChildExist == '1'?'<p class="tree-arrow cursor"><img src="'+ basePath +'/static/user/img/icon_select_down.png"></p><p>' + ao4.orgName + '</p>':'<p style="margin-left: 8px;margin-right: 6px;">' + ao4.orgName + '</p>';
													str += '</div>';
													str += '</div>';
													if (ao4.isChildExist == '1' && ao3.children.length > 0) {
														str += '<ul class="tree-five">';
														$.each(ao4.children, function (index, ao5) {
															str += '<li>';
															str += '<div class="tree-children">';
															str += '<div>';
															str += '<p class="mr5px"><input lay-filter="switchTest" type="checkbox" '+(ao5.authType == 0?' ':checked="checked")+' data-state="0" data-parentorgid="' + ao5.parentOrgId + '" id="' + ao5.orgId + '" name="" lay-skin="primary"></p>';
															str += ao5.isChildExist == '1'?'<p class="tree-arrow cursor"><img src="'+ basePath +'/static/user/img/icon_select_down.png"></p><p>' + ao5.orgName + '</p>':'<p style="margin-left: 8px;margin-right: 6px;">' + ao5.orgName + '</p>';
															str += '</div>';
															str += '</div>';
															str += '</li>';
														})
														str += '</ul>';
													}
													str += '</li>';
												})
												str += '</ul>'
											}
											str += '</li>';
										})
										str += '</ul>';
									}
									str += '</li>';
								})
								str += '</ul>';
							}
							str += '</li>';
						});
						str += '</ul>';
					}
					str += '';
					$("#treeThree .tree-con-box").html(str);
					//授权机构树点击功能初始化
					treeThreeInit();
				});
			}
		})
	}

	/**
	 * 判断是否为空
	 */
	function isNull(value) {
		return value == null || value === "" || value === undefined;
	}

	/**
	 * layer msg
	 */
	function layerMsg(msg){
		var layer;
		layui.use(['layer'], function() {
			layer = layui.layer;
			layer.ready(function(){
				layer.msg(msg);
			});
		});
	}

	/**
	 * layer result
	 */
	function layerResult(msg,type){
		var layer;
		layui.use(['layer'], function() {
			layer = layui.layer;
			layer.ready(function(){
				layer.msg(msg, {icon: type, time:1500});
			})
		});
	}

	/**
	 * layer checkbox
	 */
	function checkBoxInit(){
		layui.use(['form'], function() {
			var form = layui.form;
			form.render('checkbox');
		});
	}

	/**
	 * 添加用户
	 */
	function addUser(){
		var userNo = $("input[name=userNo]").val();
		var loginName = $("input[name=loginName]").val();
		var userName = $("input[name=userName]").val();
		var phone = $("input[name=phone]").val();
		var post = $("input[name=post]").val();
		var dept = $("input[name=dept]").val();
		var selectParentOrg = $("#selectParentOrg").data("orgid");
		var authRole =  $(".selectRole").map(function(){
			return $(this).data("id");
		}).get().join("-");
		var authOrg = $("#treeThree input[type=checkbox]:checked").map(function(){
			return this.id;
		}).get().join("-");

		if(isNull(loginName)){
			layerMsg("用户账号不能为空！");
			return;
		}
		if(isNull(userName)){
			layerMsg("用户姓名不能为空！");
			return;
		}
		if(isNull(selectParentOrg)){
			layerMsg("上级组织不能为空！");
			return;
		}
		if(isNull(phone)){
			layerMsg("手机号不能为空！");
			return;
		}
		if (!/^(((13[0-9]{1})|(15[0-9]{1})|(17[0-9]{1})|(18[0-9]{1})|(19[0-9]{1}))+\d{8})$/.test(phone)){
			layerMsg("请正确填写您的手机号码！");
			return;
		}

		//console.log("authRole="+authRole);
		var args=[];
		args.push(userNo);
		args.push(loginName);
		args.push(userName);
		args.push(phone);
		args.push(post);
		args.push(dept);
		args.push(selectParentOrg);
		args.push(authRole);
		args.push(authOrg);
		if(isNull(userNo)){
			confirmCon("确认要新建用户吗？",addUserCommit, args);
		}else{
			confirmCon("确认要修改用户吗？",addUserCommit, args);
		}


	}

	/**
	 * 确认后提交
	 */
	function addUserCommit(userNo,loginName,userName,phone,post,dept,selectParentOrg,authRole,authOrg){
		// console.log("userNo="+userNo);
		// console.log("loginName="+loginName);
		// console.log("userName="+userName);
		// console.log("phone="+phone);
		// console.log("post="+post);
		// console.log("dept="+dept);
		// console.log("selectParentOrg="+selectParentOrg);
		// console.log("authRole="+authRole);
		// console.log("authOrg="+authOrg);
		$.ajax({
			url:basePath + "/user/save",
			type:"post",
			dataType:"json",
			data:{"userNo":userNo,"userName":userName,"loginName":loginName,"phone":phone,"post":post,"dept":dept,"orgId":selectParentOrg,"authRole":authRole,"authOrg":authOrg,"postType":"1"},
			beforeSend: function(){
				$("#addBtn").css("pointer-events", "none");
			},
			success:function (data) {
				if(userNo==null||userNo==""){
					if(data.code==200){
						layer.msg("添加成功", {icon: 1, time:1500},function(){
							window.location.href=basePath+"/user/listPage";
						});
					}else{
						layer.msg(data.msg, {icon: 2, time:1500});
					}
				}else{
					if(data.code==200){
						layer.msg("修改成功", {icon: 1, time:1500},function(){
							window.location.href=basePath+"/user/listPage";
						});
					}else{
						layer.msg(data.msg, {icon: 2, time:1500});
					}
				}
				$("#addBtn").css("pointer-events", "auto");
			}
		})
	}

	/**
	 * 修改初始化
	 */
	function editUserInit(){
		var userNo = '[[${userNo}]]';
		if(!isNull(userNo)){
			$.ajax({
				type:"post",
				url:basePath+"/user/getUserById",
				dataType:"json",
				data:{"userNo":userNo},
				success:function(rst){
					$("input[name=userNo]").val(rst.data.USER_NO);
					$("input[name=loginName]").val(rst.data.LOGIN_NAME);
					$("input[name=userName]").val(rst.data.USER_NAME);
					$("input[name=phone]").val(rst.data.PHONE);
					$("input[name=post]").val(rst.data.POST);
					$("input[name=dept]").val(rst.data.DEPT);
					$("#selectParentOrg").val(rst.data.ORG_NAME);
					$("#selectParentOrg").data("orgid",rst.data.ORG_ID);
					//回显授权角色
					if(rst.data.AUTH_ROLE) {
						var arrLi = rst.data.AUTH_ROLE.split(",");
						arrLi.forEach(function (obj, index) {
							//获取角色名字
							var name = getRoleName(obj);
							var html = '';
							html += '<li class="selectRole" data-id="' + obj + '" style="margin-bottom: 8px">';
							html += '<span>' + name + '</span>';
							html += '<em><img src="' + basePath + '/static/user/img/icon_delete.png" data-id="' + obj + '" onclick="removeRole(this)"></em>'
							html += '</li>';
							$("#roleConBtn").before(html);
							selectRoleStr+=obj+",";
						})
					}
					$("#actionTitle").html("修改用户");
					$("title").html("用户修改");
				}
			})
		}
	}

	/**
	 * 授权角色弹窗
	 */
	function roleCon(){
		var userNo = '[[${userNo}]]';
		var html='';
		html+='<div id="pop-con">';
		html+='<div class="pop-up">';
		html+='<div>';
		html+='<div class="pop-title relative overflow mb15px">';
		html+='<span class="ml15px">添加授权角色</span>';
		html+='<p class="right"><img src="'+basePath+'/static/img/close_icon.png" class="block pop-close"><p>';
		html+='</div>';
		html+='<nav class="add-person mt20px mb10px">';
		html+='<ul>';
		$.ajax({
			type:"post",
			url:basePath+"/user/getRoleList",
			dataType:"json",
			data:{"userNo":userNo},
			async:false,
			success:function(rst){
				$.each(rst.data,function(index,obj){
					if(selectRoleStr.indexOf(","+obj.id+",")!=-1){
						html+='<li style="margin-right: 30px;" data-state="1" class="cur-green" data-id="'+obj.id+'" onclick="selectRole(this)">'+obj.name+'</li>';
					}else{
						html+='<li style="margin-right: 30px;" data-state="0" data-id="'+obj.id+'" onclick="selectRole(this)">'+obj.name+'</li>';
					}
				});
			}
		})
		html+='</ul>';
		html+='</nav>';
		html+='<div class="btn-con textCenter">';
		html+='<span class="btn-one">取&nbsp;消</span>';
		html+='<span class="btn-two">提&nbsp;交</span>';
		html+='</div>';
		html+='</div>';
		html+='</div>';
		html+='</div>';

		layui.use(['element', 'layer'], function() {
			var element = layui.element;
			var layer = layui.layer;
			var indexview=layer.open({
				type: 1
				,title: false //不显示标题栏
				,closeBtn: false
				//新建组织
				,area: ['570px','']
				,shade: 0.6
				,id: 'role' //设定一个id，防止重复弹出
				/*,btn: ['确认支付']*/
				,btnAlign: 'c'
				,moveType: 1 //拖拽模式，0或者1
				,shadeClose: true //设置允许点遮罩关闭
				,content: html,
				success:function(){
					$(".btn-one").unbind().click(function () {
						layer.close(indexview);
					})
					$(".btn-two").unbind().click(function () {
						//移除上次选择的角色
						$("#roleConBtn").parent().find("li").each(function(){
							$(this).remove();
						});
						//追加选择角色
						var arrLi = $(".add-person .cur-green");
						Array.prototype.forEach.call(arrLi, function(obj, index) {
							var id = $(obj).data("id");
							var name = $(obj).html();
							var html = '';
							var checkId=id+",";
							html+='<li class="selectRole" data-id="'+id+'" style="margin-bottom: 8px">';
							html+='<span>'+name+'</span>';
							html+='<em><img src="'+basePath+'/static/user/img/icon_delete.png" data-id="'+id+'" onclick="removeRole(this)"></em>'
							html+='</li>';

							$("#roleConBtn").before(html);
						})
						layer.closeAll();
					})
					$(".pop-close").unbind().click(function () {
						layer.closeAll();
					})
				},
			});
		});
	}

	/**
	 * 选中取消角色
	 */
	function selectRole(obj) {
		var state = $(obj).data("state");
		if(state==0){
			selectRoleStr+=$(obj).data("id")+",";
			$(obj).data("state","1");
			$(obj).addClass("cur-green");
		}else if(state==1){
			$(obj).data("state","0");
			$(obj).removeClass("cur-green");
		}
	}

	/**
	 * 移除角色
	 */
	function removeRole(obj){
		var id = $(obj).data("id");
		$(obj).parent().parent().remove();
		if(selectRoleStr.length>1){
			selectRoleStr = selectRoleStr.substr(0,selectRoleStr.length-1);
			var arr = selectRoleStr.split(",");
			var tmpSelectRoleStr = ",";
			arr.forEach(function(value,i){
				if(value!=id){
					tmpSelectRoleStr+=value+",";
				}
			})
		}
		selectRoleStr = tmpSelectRoleStr;
	}

	/**
	 * 获取角色名字
	 */
	function getRoleName(roleNo){
		var name="";
		$.ajax({
			type:"post",
			url:basePath+"/user/getRoleInfo",
			dataType:"json",
			data:{"roleNo":roleNo},
			async:false,
			success:function(rst){
				name = rst.info.name;
			}
		})
		return name;
	}

</script>
</body>
</html>
